package com.jp.vn.main;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Vector;

import com.jp.vn.Object.Question;
import com.jp.vn.Object.Data;
import android.app.Activity;
import android.os.Bundle;

public class AlphaPractiseType1Activity extends Activity {

	Random r = new Random();
	ArrayList<Question> arrayQuestion = new ArrayList<Question>();
	Question question;
	Vector<String> asw,v;
	int ans;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_alpha_practise_type1);
		
		arrayQuestion = creatQuestions(46);
		
	}

	public ArrayList<Question> creatQuestions(int length) {
		ArrayList<Question> arrayQues = new ArrayList<Question>();
		for (int i = 0; i < length; i++) {
			question = new Question();
			question.setQuestion(Data.arrayLatin[i]);
			question.setAnswerCorrect(Data.arrayHira[i]);
			
			asw = randomAnswer(question.getAnswerCorrect());
			question.setAnswerA(asw.get(0));
			question.setAnswerB(asw.get(1));
			question.setAnswerC(asw.get(2));
			question.setAnswerD(asw.get(3));
			
			arrayQues.add(question);
			Collections.shuffle(arrayQues);
		}
		return arrayQues;
	}
	
	public Vector<String> randomAnswer(String correctAnswer) {
		v = new Vector<String>();
		v.add(correctAnswer);
		do {
			ans = r.nextInt(Data.arrayHira.length);
			String tmp = Data.arrayHira[ans];
			if (!v.contains(tmp)) {
				v.add(tmp);
			}
		} while (v.size() < 4);

		Collections.shuffle(v);
		return v;
	}
	
	public void getQuestion(int id){
		
	}

}
